//
//  JOTitleButton.m
//  网易彩票
//
//  Created by song on 15/2/8.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOTitleButton.h"

@interface JOTitleButton()

@property(nonatomic , strong) UIFont *titleFont;

@end

@implementation JOTitleButton


//-(void)awakeFromNib
//{
//    self.titleFont  =[UIFont systemFontOfSize:14];
//    self.titleLabel.font = self.titleFont;
//    self.imageView.contentMode =UIViewContentModeCenter;
//}

//-(void)willMoveToSuperview:(UIView *)newSuperview
//{
//    self.titleFont  =self.titleLabel.font;
//}

-(id)initWithCoder:(NSCoder *)decoder
{
    if(self = [super initWithCoder:decoder])
    {
        self.titleFont  =[UIFont systemFontOfSize:14];
        self.titleLabel.font = self.titleFont;
        self.imageView.contentMode =UIViewContentModeCenter;
    }
    return self;
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleX =0;
    CGFloat titleY =0;
    
    NSDictionary *attrs =@{NSFontAttributeName :self.titleFont};
    CGFloat titleW = [self.currentTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.width;
    CGFloat titleH = contentRect.size.height;
    return CGRectMake(titleX, titleY, titleW, titleH);
    
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageW = 30;
    CGFloat imageX = contentRect.size.width - imageW;
    
    CGFloat imageY = 0;
    CGFloat imageH = contentRect.size.height;
    
    return  CGRectMake(imageX, imageY, imageW, imageH);
}

@end
